﻿/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://github.com/shenyczz/CSharpKit
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/

using System;
using CSharpKit.Numerics.Distributions;
using CSharpKit.Numerics.LinearAlgebra.Solvers;
using CSharpKit.Numerics.Theories;

namespace CSharpKit.Numerics.LinearAlgebra
{
    internal class MatrixBuilderDouble : MatrixBuilder<double>
    {
        // Dense

        /// <summary>
        /// 密集矩阵
        /// </summary>
        /// <param name="storage"></param>
        /// <returns></returns>
        public override Matrix<double> Dense(IMatrixStorage storage)
        {
            var result = default(Matrix<double>);

            if (storage is MatrixStorageDense<double> dense)
            {
                result = new Doubles.DenseMatrix(dense);
            }

            return result;
        }




        // Sparse

        public override Matrix<double> Sparse(IMatrixStorage storage)
        {
            return new Doubles.SparseMatrix(storage as MatrixStorage<double>);
        }



        // Diagonal

        public override Matrix<double> Diagonal(IMatrixStorage storage)
        {
            return new Doubles.DiagonalMatrix(storage as MatrixStorage<double>);
        }




        /// <summary>
        /// 
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <param name="distribution"></param>
        /// <returns></returns>
        public override Matrix<double> Random(int rows, int columns, IContinuousDistribution distribution)
        {
            return Dense(rows, columns, Generator.Random(rows * columns, distribution));
        }



        public override IIterationStopCriterion<double>[] IterativeSolverStopCriteria(int maxIterations = 1000)
        {
            return new IIterationStopCriterion<double>[]
            {
                //new FailureStopCriterion<double>(),
                //new DivergenceStopCriterion<double>(),
                //new IterationCountStopCriterion<double>(maxIterations),
                //new ResidualStopCriterion<double>(1e-12)
            };
        }

        //}}@@@
    }


}

